package easyjava.function;

import java.util.function.BooleanSupplier;

/**
 * when 方法
 *
 */
public interface WhenFunction {
		
	class WhenFun{
		
		private boolean isHandle = false;
		
		public WhenFun when(boolean condition,Runnable action) {
			if(condition) {
				if(!isHandle) isHandle = true;
				action.run();
			}
			return this;
		}
		
		public WhenFun when(BooleanSupplier boolFun,Runnable action) {
			return this.when(boolFun.getAsBoolean(), action);
		}
		
		public WhenFun other(Runnable action) {
			if(!isHandle) {
				isHandle = true;
				action.run();
			}
			return this;
		}
		
		public void last(Runnable action) {
			action.run();
		}
	};
	
	static WhenFun when(boolean condition,Runnable action) {
		return new WhenFun().when(condition, action);
	}
	
	static WhenFun when(BooleanSupplier boolFun,Runnable action) {
		return new WhenFun().when(boolFun, action);
	}
}
